package com.pi.iot.repository.constants;

public enum AlarmTypeEnum {
//1：翘锁报警  2：假锁报警 3：电池欠压报警  4：外接电源掉电报警 5：禁试报警 6：水浸报警  7：高温报警
  LOCK_OK(0x00, "未触发报警"),
  LOCK_PIC(0x01, "翘锁报警"),
  LOCK_UNLOCK(0x02, "假锁报警"),
  LOCK_LOW_BATTERY(0x04, "电池欠压报警"),
  LOCK_RETRY(0x08, "禁试报警"),
  LOCK_WATER_LOGGING(0x10, "水浸报警"),
  LOCK_OVER_HEATED(0x20, "高温报警"),
  LOCK_OFF_BATTERY(0xFD, "外接电源掉电报警"),
  LOCK_OFFLINE(0xFE, "离线报警"),

  ;
  private int type;
  private String desc;
  private AlarmTypeEnum(int type, String desc) {
    this.type = type;
    this.desc = desc;
  }
  public int getType() {
    return type;
  }
  public String getDesc() {
    return desc;
  }
  
  public static AlarmTypeEnum getAlarmType(Integer type) {
    if(null != type){
      if(0 == type)
        return AlarmTypeEnum.LOCK_OK;
      for(AlarmTypeEnum alarmType:AlarmTypeEnum.values()){
        if((type.intValue() & alarmType.getType()) == alarmType.getType() && alarmType != LOCK_OK)
          return alarmType;
      }
    }
    return null;
  }
  
  public static boolean isOK(Integer type){
    if(null == type || type == AlarmTypeEnum.LOCK_OK.getType())
      return true;
    return false;
  }
  
  public static boolean isUnlockAlarm(Integer type){
    if(null == type)
      return false;
    return (AlarmTypeEnum.LOCK_UNLOCK.getType() & type ) == AlarmTypeEnum.LOCK_UNLOCK.getType();
  }
  public static boolean isLowBatteryAlarm(Integer type){
    if(null == type)
      return false;
    return (AlarmTypeEnum.LOCK_LOW_BATTERY.getType() & type ) == AlarmTypeEnum.LOCK_LOW_BATTERY.getType();
  }
  public static String getAlarmDesc(Integer type){
    AlarmTypeEnum alarmTypeEnum = getAlarmType(type);
    return null != alarmTypeEnum? alarmTypeEnum.getDesc() : "未知报警";
  }
}
